<template>
  <el-card>
    <div slot="header">
      <div style="display: inline-block; line-height: 45px;">
        <span style="font-size: 18px; font-weight: 600; color: rgb(73, 80, 96);">Contest Problem List</span>
      </div>
    </div>
    <el-table
        :data="model.data"
        empty-text="加载中"
        :header-cell-style="{color:'#606266'}"
        @row-click="handleProblemView">

      <el-table-column
          align="center"
          width="100"
          label="num">
        <template slot-scope="scope">
          {{ scope.row.num | mappingToCharacter }}

        </template>
      </el-table-column>
      <el-table-column
          align="center"
          width="100"
          prop="problemId"
          label="ID">
      </el-table-column>
      <el-table-column
          align="center"
          prop="title"
          label="Title">
      </el-table-column>
      <el-table-column
          label="状态"
          align="center"
          width="100">
        <template slot-scope="scope">
          {{ !scope.row.submitted ? '未提交' : '已提交' }}
        </template>
      </el-table-column>
      <!--<el-table-column-->
      <!--align="center"-->
      <!--label="AC/Submit">-->
      <!--<template slot-scope="scope">-->
      <!--{{getACRate(scope.row)}}-->
      <!--</template>-->
      <!--</el-table-column>-->
    </el-table>
  </el-card>
</template>

<script>
import {getContestProblemList} from '@/network/contest'
import {PROBLEM_STATUS} from '../../../utils/constants'

export default {
  mounted() {
    this.init()
  },
  data() {
    return {
      STATUS_SET: PROBLEM_STATUS.STATUS_SET,
      STATUS_COLOR_SET: PROBLEM_STATUS.STATUS_COLOR_SET,
      model: {
        data: []
      }
    }
  },
  methods: {
    init: function () {
      const contestId = this.$route.params.contestId
      getContestProblemList(contestId).then(res => {
        console.log(res.data)
        this.model.data = res.data
      }).catch(_ => {
        console.log(_)
      })
    },
    handleProblemView: function (row) {
      const contestId = this.$route.params.contestId
      this.$router.push({
        name: 'contest-problem-detail',
        params: {
          contestId: contestId,
          problemId: row.problemId
        }
      })
    },
    getACRate: function (key) {
      return key.accept.toString() + '/' + key.submit.toString()
    }
  },
  watch: {
    '$route': function (newVal, oldVal) {
      if (newVal !== oldVal) {
        this.init()
      }
    }
  }
}
</script>

<style>

</style>
